<template>
  <div class='container'>
    <el-form :model="form" label-width="80px" :rules="rules">
      <el-form-item label="所选学科" style="width: 100%" v-if="!$route.query.id">
        <el-select v-model="form.subjectID" placeholder="请选择" style="width: 100%">
          <el-option :label="item.label" :value="item.value" v-for="item in addTagList"></el-option>
        </el-select>
      </el-form-item>
      <el-form-item label="目录名称" style="width: 100%" prop="tagName">
        <el-input
          v-model="form.tagName"
          autocomplete="off"
          placeholder="请输入目录名称"></el-input>
      </el-form-item>
    </el-form>
    <div slot="footer" class="dialog-footer">
      <el-button @click="$emit('chang')">取 消</el-button>
      <el-button type="primary" @click="AddTag">确 定</el-button>
    </div>
  </div>
</template>
<script>
import { add, update } from '@/api/hmmm/tags'
export default {
  name: 'tagADD',
  props: {
    addTagList: {
      type: [Object, Array],
      required: true
    },
    // 每一行的值
    currentData: {
      type: [Object, Array],
      required: true
    },
    tex: {
      type: String,
      required: true
    }
  },
  data () {
    return {
      form: {
        subjectID: this.currentData.subjectID,
        tagName: this.currentData.tagName,
        id: this.currentData.id
      },
      rules: {
        tagName: [
          { required: true, message: '请输入目录名称', trigger: 'blur' },
          { min: 3, max: 5, message: '长度在 3 到 5 个字符', trigger: 'blur' }
        ]
      }
    }
  },
  methods: {
    // 新增标签
    async AddTag () {
      if (!this.form.id) {
        try {
          await add(this.form)
          this.$emit('chang')
          this.form = {}
        } catch (err) {}
      } else {
        try {
          await update(this.form)
          this.$emit('chang')
          this.form = {}
        } catch (err) {}
      }
    },
    getData (e) {
      console.log(e)
    }
  },
  created () {
    console.log(this.currentData)
  }
}

</script>

<style scoped lang='less'></style>
